package com.yangye.springclouddemosharding.controller;

import com.yangye.springclouddemosharding.entity.Temperature;
import com.yangye.springclouddemosharding.service.TemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yangye
 * @date 2020/08/31
 */
@RestController
@RequestMapping("/sharding")
public class TemperatureController {

	@Autowired
	private TemperatureService temperatureService;

	@GetMapping("/save")
	long save(Long merchantId) {
		Temperature temp = new Temperature();
		temp.setReportTempCarWheel(new BigDecimal(1.0));
		temp.setReportTempCarBody(new BigDecimal(2.0));
		temp.setCarLicense("111");
		temp.setDeviceId(merchantId);
		temp.setFeveredCarBody(1);
		temp.setFeveredCarWheel(1);
		temp.setPhotoUrl("url");
		temp.setReportTimestamp(BigInteger.valueOf(11));
		temp.setMistake(1);
		temp.setIsInvalid(1);
		temp.setHandled(1);
		Long id = temperatureService.save(temp);
		return id;
	}

	@GetMapping("/page")
	List<Temperature> list() {
		return temperatureService.findPage(0, 100);
	}
}
